package com.inspur2

import org.apache.spark.{SparkConf, SparkContext}

object ChampionsNumber {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      //      .setMaster("spark://192.168.66.88:7077")
      .setMaster("local")
      .setAppName("Champions count")
    val sc = new SparkContext(conf)

    val champions = sc.textFile("hdfs://192.168.66.88:8020/0622/clear_data/part-00000")

    champions
      .map(_.split(","))
      .map(x=>(x(2), 1))
      .reduceByKey(_+_)
      .sortBy(x => x._2)
      .repartition(1)
//      .foreach(println)
      .saveAsTextFile("hdfs://192.168.66.88:8020/0622/nba_champions_number")
  }

}

//(芝加哥公牛队,6)
//(纽约尼克斯队,2)
//(费城76人队,3)
//(萨克拉门托国王队,1)
//(华盛顿奇才队,2)
//(多伦多猛龙队,1)
//(迈阿密热火队,3)
//(圣安东尼奥马刺队,5)
//(波士顿凯尔特人队,17)
//(金州勇士队,6)
//(洛杉矶湖人队,16)
//(克里夫兰骑士队,1)
//(休斯顿火箭队,2)
//(密尔沃基雄鹿队,1)
//(底特律活塞队,3)
//(俄克拉荷马城雷霆队,1)
//(波特兰开拓者队,1)
//(亚特兰大老鹰队,1)
//(达拉斯独行侠队,1)